void printXML(vector<struct rect> &rlist){
	cout<<"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"<<endl;
	cout<<"<space x=\""<<width<<"\" y=\""<<height<<"\">"<<endl;
	for(int i=0;i<rlist.size();i++){
		cout<<"<rect name=\"\" x1=\""<<rlist[i].x<<"\" y1=\""<<rlist[i].y<<"\" x2=\""<<rlist[i].x+rlist[i].w<<"\" y2=\""<<rlist[i].y+rlist[i].h<<"\"  w=\""<<rlist[i].w<<"\" h=\""<<rlist[i].h<<"\" />"<<endl;
	}
	cout<<"</space>"<<endl;

}


int main(){
	vector<struct rect>rectangles;
	vector<int>skyline;
	cin>>width>>height;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		struct rect r;
		cin>>r.w>>r.h;
		if(r.h>r.w)
			swap(r.h,r.w);
		r.x=0;
		r.x=0;
		rectangles.push_back(r);
	}
	sort(rectangles.begin(),rectangles.end(),comparew);
	for(int i=0;i<width;i++){
		skyline.push_back(0);
	}
	for(int i=0;i<rectangles.size();i++){
//		cout<<rectangles[i].w<<" "<<rectangles[i].h<<endl;
	}
	int h1,h2,h3;
	vector<struct rect>rlist1=packleftmost(rectangles,skyline,&h1);
	vector<struct rect>rlist2=packtotall(rectangles,skyline,&h2);
	vector<struct rect>rlist3=packtoshort(rectangles,skyline,&h2);
	if(h1<h2){
		if(h1<h3)
			printXML(rlist1);
		else
			printXML(rlist3);
	}else{
		if(h2<h3)
			printXML(rlist2);
		else
			printXML(rlist3);
	}

//	sort(rlist.begin(),rlist.end(),comparew);


}

